<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="110px">
        <el-form-item label="工单编号" prop="workNo">
          <el-input v-model="queryParams.workNo" placeholder="请输入工单编号" clearable size="small"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="提交时间" prop="createDay">
          <el-date-picker v-model="queryParams.createDay" type="date" value-format="yyyy-MM-dd" placeholder="选择日期"  @keyup.enter.native="handleQuery" ></el-date-picker>
        </el-form-item>
        <el-form-item label="问题分类" prop="category">
          <el-select multiple v-model="queryParams.category" placeholder="请选择问题分类">
            <el-option v-for="contract in categoryArray" :key="contract.dictLabel" :label="contract.dictLabel"
              :value="contract.dictLabel"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="联系方式" prop="contactNumber">
          <el-input v-model="queryParams.contactNumber" placeholder="请输入联系方式" clearable size="small"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="tabList">
        <el-table-column label="工单编号" align="center" prop="workNo" />
        <el-table-column label="提交时间" align="center" prop="createTime" />
        <el-table-column label="问题分类" align="center" prop="category" />
        <el-table-column label="问题描述" align="center" prop="description">
          <template slot-scope="scope">
            <div @click="lookNotes(scope.row)" style="color:cornflowerblue;cursor: pointer;">查看</div>
          </template>
        </el-table-column>
        <el-table-column label="问题截图" align="center" prop="imgUrl">
          <template slot-scope="scope">
            <div @click="imgUrlClick(scope.row)" style="color:cornflowerblue;cursor: pointer;">查看</div>
          </template>
        </el-table-column>
        <el-table-column label="联系方式" align="center" prop="contactNumber" />
        <el-table-column label="对工程师评价" align="center" prop="evaluate" :formatter="evaluateFormatter"/>
        <el-table-column label="是否解决问题" align="center" prop="resolve" :formatter="resolveFormatter"/>
        <el-table-column label="操作" align="center" prop="">
          <template slot-scope="scope">
            <div v-if="scope.row.status==1" style="color:cornflowerblue;cursor: pointer;">
              <span style="margin-right: 10px;" @click="replyClick(scope.row)" v-hasPermi="['admin:feedback:reply']">回复</span>
              <span @click="complaintClick(scope.row)" v-hasPermi="['admin:feedback:complain']">转投诉</span> 
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
      <el-dialog :title="title" :close-on-click-modal="false" :visible.sync="open" width="500px" append-to-body>
        <div class="popupCont" v-if="!inputDisabled">{{ description }}</div>
        <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="replyContent" v-if="inputDisabled"></el-input>
        <div slot="footer" class="quesEditBtn">
          <el-button type="primary" @click="submit" v-if="inputDisabled">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
      <el-dialog :visible.sync="picShow" title="问题截图">
        <el-image style="width: 100px; height: 100px;margin:0 10px 10px 0" :src="item.url"  v-for="(item,index) in srcList" :preview-src-list="[item.url]"> </el-image>
      </el-dialog>
    </div>
  </template>
    
  <script>
  import { feedbackList , reply ,complain} from "@/api/feedback/feedback";
  import { getToken } from '@/utils/auth'
  export default {
    name: "Knowledge",
    components: {
    },
    data() {
      return {
        // 遮罩层
        loading: false,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 表格数据
        tabList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        picShow:false,
        companyTypeOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          workNo:null,
          createDay:null,
          category:null,
          contactNumber:null
        },
        textarea:'',
        description:'',
        evaluateArray:[],//满意度评价
        resolveArray:[],//是否解决
        categoryArray:[],//问题分类
        replyContent:'',
        inputDisabled:false,
        workNo:'',
        srcList:[]
      };
    },
    created() {
      this.getList();
      //在字典查询-满意度
      this.getDicts("evaluate").then(response => {
        this.evaluateArray = response.data;
      });
      //是否解决
      this.getDicts("is_resolve").then(response => {
        this.resolveArray = response.data;
      });
      //问题分类
      this.getDicts("category").then(response => {
        this.categoryArray = response.data;
      });
    },
    methods: {
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 查询产品入库列表 */
      getList() {
        this.loading = true;
        feedbackList(this.queryParams).then(response => {
          this.tabList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      //查看问题描述
      lookNotes(row){
        this.description = row.description
        this.title = '问题描述'
        this.inputDisabled = false
        this.open = true
      },
      //问题截图
      imgUrlClick(row){
        this.srcList = []
        if (row.imgUrl){
          this.srcList = JSON.parse(row.imgUrl)
        }
        this.picShow = true
      },
      //回复
      replyClick(row){
        this.title = '回复'
        this.open = true
        this.inputDisabled = true
        this.workNo = row.workNo
      },
      //回复确定
      submit(){
        reply({replyContent:this.replyContent,workNo:this.workNo}).then(response => {
          if(response.code == "200"){
            this.msgSuccess(response.msg);
            this.open = false
            this.getList()
          }
        });
      },
      //转投诉
      complaintClick(row){
        complain(row.workNo).then(response => {
          if(response.code == "200"){
            this.msgSuccess(response.msg);
            this.open = false
            this.getList()
          }
        });
      },
      //满意度
      evaluateFormatter(row, column) {
        return this.selectDictLabel(this.evaluateArray, row.evaluate);
      },
      //满意度
      resolveFormatter(row, column) {
        return this.selectDictLabel(this.resolveArray, row.resolve);
      },
      cancel(){
        this.open=false
      }
    }
  };
  </script>
  <style>
    .popupCont{
      min-height: 80px;
      padding: 10px ;
      font-size: 14px;
      color:#333;
      border-radius: 6px;
      border:1px solid #999;
    }
    .quesEditBtn{
      text-align: center;
    }
  </style>
    